package org.zsl.controller;

import org.zsl.model.User;
import org.zsl.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginController extends HttpServlet {

    private UserService userService=new UserService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

          User user = new User();
          // user.username =   req.getParameter("username");

         //  user.setUsernname( req.getParameter("username"));

           String username  = req.getParameter("username");
           user.setUsername(username);

           String password = req.getParameter("password");
           user.setPassword(password);

           Boolean isSuccess=  userService.login(user);

           resp.getWriter().write(isSuccess.toString());


    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("this is a post request！");

        User user = new User();
        // user.username =   req.getParameter("username");

        //  user.setUsernname( req.getParameter("username"));

        String username  = req.getParameter("username");
        user.setUsername(username);

        String password = req.getParameter("password");
        user.setPassword(password);

        Boolean isSuccess=  userService.login(user);

        resp.getWriter().write(isSuccess.toString());

    }
}
